<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activIds']))
{
  header("Location:checkLogin.php");
}
else
{
  $o=0;
  $invoiceNoSelected = "";
  $contractArray = array();  
if(isset($_GET['contractId']))
{
  if($_GET['contractId'] > 0)
  {
    $selectContract = "SELECT DATE_FORMAT(contDate,'%d-%m-%Y')AS contDate,contQty,conPrice,conValue,numOfInvoice,advAmount,	
                                  DATE_FORMAT(advRptDate,'%d-%m-%Y')AS advRptDate
                             FROM contract
                           WHERE contract.contractId = ".$_GET['contractId'];
    $selectContractRes = mysql_query($selectContract);
    while($contractRow = mysql_fetch_array($selectContractRes))
    {
    	$contractArray[$o]['contDate']        = $contractRow['contDate'];
    	$contractArray[$o]['contQty']         = $contractRow['contQty'];
    	$contractArray[$o]['conPrice']        = $contractRow['conPrice'];
    	$contractArray[$o]['conValue']        = $contractRow['conValue'];
    	$contractArray[$o]['numOfInvoice']    = $contractRow['numOfInvoice'];
    	$contractArray[$o]['advAmount']       = $contractRow['advAmount'];
    	$contractArray[$o]['advRptDate']      = $contractRow['advRptDate'];
    	$o++;
    }
    $k=0;
    $invoiceArray = array();
    $selectInvoice = "SELECT userdoc.invoiceId,invoiceNo
                        FROM userdoc
                       JOIN  invoice ON  invoice.invoiceId = userdoc.invoiceId
                       WHERE userdoc.contractId =".$_GET['contractId']."
                       GROUP BY invoiceNo";
    $selectInvoiceRes = mysql_query($selectInvoice);
    while($invoiceRow = mysql_fetch_array($selectInvoiceRes))
    {
    	$invoiceArray['invoiceId'][$k] = $invoiceRow['invoiceId'];
    	$invoiceArray['invoiceNo'][$k] = $invoiceRow['invoiceNo'];
    	$k++;
    }
  }
}
include("bottom.php");
$smarty->assign("contractArray",$contractArray);
if(isset($_GET['contractId']))
{
  $smarty->assign("invoiceArray",$invoiceArray);	
}

$smarty->assign("invoiceNoSelected",$invoiceNoSelected);
$smarty->display("getContractDetail.tpl");
}
?></i>